//
//  SLNavigationBar.swift
//  sulit-loan
//
//  Created by 王刚锋 on 2025/4/5.
//  Copyright © 2025 coolBoy. All rights reserved.
//

import UIKit

class SLNavigationBar: UIView {
    var onClickLeftButton:(()->())?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupView()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
//        setupView()
    }
    
    class func create() -> SLNavigationBar {
        let frame = CGRect(x: 0, y: 0, width: DevConfig.width, height: CGFloat(44+DevConfig.state_height))
        return SLNavigationBar(frame: frame)
    }
    
    func setupView(){
        self.backgroundV.isHidden = true
        self.titleLabel.isHidden = false
        self.backButon.isHidden = false
    }
    
    lazy var backgroundV:UIView = {
        let view = create_view(bgColor: .clear, supView: self) { make in
            make.left.right.equalTo(0)
            make.top.equalTo(DevConfig.state_height)
            make.bottom.equalTo(0)
            make.height.equalTo(44)
        }
        return view
    }()
    var title:String? {
        willSet {
            titleLabel.text = newValue
            self.backgroundV.isHidden = false
        }
    }
    lazy var titleLabel:UILabel = {
        let label = create_label(text: "", textColor: .black, textFont: SLFontConfig.medium20,alignment: .center, supView: self.backgroundV) { make in
            make.centerX.centerY.equalToSuperview()
        }
        return label
    }()
    lazy var backButon:UIButton = {
        let button = create_button( image: IMAGE("icon_return"), supView: self.backgroundV, closure: { make in
            make.left.equalTo(15)
            make.width.height.equalTo(24)
            make.centerY.equalToSuperview()
        }, selector: (target: self, action: #selector(clickBack), event:.touchUpInside))
        button.imageView?.contentMode = .center
        return button
    }()
    @objc func clickBack(){
        if let onClickBack = onClickLeftButton {
            onClickBack()
        }
    }

}
